/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Month_Statistic.java
 *
 * Created on 2011-04-10, 19:24:48
 */

package panes;

import entities.Categorie;
import entities.Month;
import entities.Year;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import models.SummaryTableModel;
import utils.ChocoBar;
import utils.ChocoPane;

/**
 *
 * @author chocoseb
 */
public class Month_Statistic extends ChocoPane {

    SummaryTableModel _model;

    /** Creates new form Month_Statistic */
    public Month_Statistic(JFrame _parent, ChocoBar _status, Month p_month, Year p_year) {
        super(_status, _parent);
        initComponents();
        _model = new SummaryTableModel(p_month, p_year);
        tblSummary.setModel(_model);
        tblSummary.setDefaultRenderer(Object.class, new RendererAction());
//        statGraphic1.addData(510, "Logement", Color.blue);
//        statGraphic1.addData(100, "Épicerie", Color.orange);
//        statGraphic1.addData(34, "Internet", Color.RED);
//        statGraphic1.addData(1250, "Université", Color.MAGENTA);
//        statGraphic1.createGraphic();
    }

    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tblSummary = new javax.swing.JTable();

        tblSummary.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblSummary);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 524, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(293, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(168, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    public class RendererAction extends DefaultTableCellRenderer {

        public RendererAction() {
            super();
        }

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            JLabel laLabel = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (column > 0) {
                laLabel.setFont(new Font(null, Font.BOLD, 12));
                double doubleValue = (Double) value;
                String doubleString = Double.toString(doubleValue);
                if (doubleValue < 0) {
                    doubleString = "(" + doubleString + ")";
                    laLabel.setForeground(Color.red);
                } else {
                    laLabel.setForeground(Color.blue);
                }
                laLabel.setText(doubleString);
                if (row % 2 == 0){
                    laLabel.setBackground(Color.white);
                }else{
                    laLabel.setBackground(new Color(232,231,213));
                }

            } else if (column == 0) {
                laLabel.setFont(new Font(null, Font.BOLD, 12));
                if (value instanceof Categorie) {
                    Categorie c = (Categorie) value;
                    laLabel.setForeground(Color.white);
                    laLabel.setBackground(c.getColor());
                } else {
                    laLabel.setForeground(Color.black);
                    laLabel.setBackground(Color.white);
                }

            }
            if (isSelected) {
                laLabel.setBackground(laLabel.getBackground().darker());
            }
            return laLabel;
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblSummary;
    // End of variables declaration//GEN-END:variables

}
